<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
     <meta name='viewport' content='width=device-width, initial-scale=1.0'>
     <title>浏览器输出</title>
     <link rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/styles/default.min.css'>
     <script src='//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/highlight.min.js'></script>
     <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.js"></script>
</head>
<body>
    <form action="">
        <button class="btn">ajax请求</button>
        <button class="postBtn">postBtn</button>
    </form>
     <pre>
        <code style='max-height: 400px;'>
                         
        </code>
     </pre>
     <script> hljs.highlightAll(); </script>
     <script>
        let arr = [1,2,3,4,5,6]
        let obj = {
            name:'zs',
            msg:'⑥'
        }
        console.log(arr);
        console.dir('console.dir打印对象的详细信息',obj);
        console.table(arr); 

        const btn = document.querySelector('.btn')
        const postBtn = document.querySelector('.postBtn')
        btn.addEventListener('click',(e) => {
            e.preventDefault()
            $.ajax({
                method:'get',
                url:'http://localhost:5000/api',
                async:false,
                timeout:100,
                success:function(res){
                    console.log('res',res);
                },
                error:function(err){
                    console.log('err',err);
                }
            })
            console.log('ssssss');
        })

        postBtn.addEventListener('click',(e) => {
            e.preventDefault()
            // 超时时间只对异步有效
            $.ajax({
                type:"post",
                url:'http://localhost:5000/api',
                async:true,
                timeout:100,
                success:function(res){
                    console.log('res',res);
                },
                error:function(err){
                    console.log('err',err);
                },
                complete:function(XHR,TextStatus){
                    if(TextStatus=='timeout'){ //超时执行的程序
                    console.log("请求超时！");
                    }
                }
            })
            console.log('ssssss');
        })


       
     </script>
</body>
</html>